home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK1.toast / Development Kits / Mac OS / Navigation Services SDK / Examples / Sampler / Sampler ƒ / Template.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-16  |  4.3 KB  |  188 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Template.c
  3.  
  4.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. //    
  9. //    You may incorporate this sample code into your applications
  10. //    without restriction. This sample code has been provided "AS
  11. //    IS" and the responsibility for its operation is 100% yours.
  12. //    You are not permitted to redistribute the source as "Apple
  13. //    sample code" after having made changes. If you're going to
  14. //    re-distribute the source, we require that you make it clear
  15. //    in the source that the code was descended from Apple sample
  16. //    code, but that you've made changes.
  17. //    
  18.  
  19. #pragma segment AppSeg
  20.  
  21. #ifndef __GESTALT__
  22. #include <Gestalt.h>
  23. #endif
  24.  
  25. #ifndef Common_Defs
  26. #include "Common.h"
  27. #endif
  28.  
  29. short        gQuit, gQuitting;
  30. short        gDocumentCount;
  31. Document*    gDocumentList[kMaxDocumentCount];
  32. short        gFontItem, gSizeItem;
  33. short        gInBackground;
  34. Document*    gFrontDocument;
  35. short        gCanUndoDrag;
  36. WindowPtr    gUndoFrontmost, gLastFrontmost;
  37. Boolean        gCanDrag;
  38. Boolean        gCanPrint;
  39. THPrint        gPrintRecord;
  40. Boolean        gNavServicesExists;
  41.  
  42. // AppleEvent handlers:
  43. AEEventHandlerUPP    myODOCEventHandler;
  44. AEEventHandlerUPP    myQAPPEventHandler;
  45. AEEventHandlerUPP    myOAPPEventHandler;
  46. ControlActionUPP     myActionProcUPP;
  47.  
  48. // for MixedMode:
  49. #ifndef NewEventHandlerProc
  50.     #define NewEventHandlerProc(x) (EventHandlerProcPtr)x
  51. #endif
  52.  
  53. // prototypes:
  54. void InitializeToolbox(void);
  55. void InitializeGlobals(void);
  56. void SetupMenus(void);
  57. void InstallEventHandlers(void);
  58.  
  59.  
  60. // *****************************************************************************
  61. // *
  62. // *    InitializeToolbox()
  63. // *
  64. // *****************************************************************************
  65. void InitializeToolbox()
  66. {    
  67.     InitGraf(&qd.thePort);
  68.     InitFonts();
  69.     InitWindows();
  70.     InitMenus();
  71.     TEInit();
  72.     InitDialogs(0L);
  73.     InitCursor();
  74.  
  75.     MoreMasters();
  76.     MoreMasters();
  77.     MaxApplZone();
  78.  
  79.     FlushEvents(everyEvent,0);
  80. }
  81.  
  82.  
  83. // *****************************************************************************
  84. // *
  85. // *    InitializeGlobals()
  86. // *
  87. // *****************************************************************************
  88. void InitializeGlobals()
  89. {    
  90.     long result = 0;
  91.  
  92.     gQuit             = gQuitting = false;
  93.     gDocumentCount     = 0;
  94.     gFontItem         = gSizeItem = 0;
  95.     gInBackground     = false;
  96.     gCanUndoDrag     = slCantUndo;
  97.     gPrintRecord    = nil;
  98.  
  99.     if ((Gestalt(gestaltDragMgrAttr,&result) != noErr) || (!(result & (1 << gestaltDragMgrPresent))))
  100.         gCanDrag = false;
  101.     else
  102.         gCanDrag = true;
  103.  
  104.     gCanPrint = false;
  105.  
  106.     // Check for Navigation Services 
  107.     gNavServicesExists = NavServicesAvailable();
  108. }
  109.  
  110.  
  111. // *****************************************************************************
  112. // *
  113. // *    SetupMenus()
  114. // *
  115. // *****************************************************************************
  116. void SetupMenus()
  117. {    
  118.     Handle        theMenuBar;
  119.     Str255        theStr;
  120.  
  121.     theMenuBar = GetNewMBar(MenuBarID);
  122.  
  123.     SetMenuBar(theMenuBar);
  124.     DisposeHandle(theMenuBar);
  125.  
  126.     AppendResMenu(GetMenuHandle(idAppleMenu),'DRVR');
  127.  
  128.     GetIndString(theStr,MenuStringsID,slCantUndo);
  129.     SetMenuItemText(GetMenuHandle(idEditMenu),iUndo,theStr);
  130.  
  131.     DrawMenuBar();
  132. }
  133.  
  134.  
  135. // *****************************************************************************
  136. // *
  137. // *    InstallEventHandlers()
  138. // *
  139. // *****************************************************************************
  140. void InstallEventHandlers()
  141. {
  142.     long     result = 0;
  143.     OSErr     theErr = noErr;
  144.     
  145.     theErr = Gestalt(gestaltAppleEventsAttr,&result);
  146.     if (theErr == noErr)
  147.         {
  148.         myODOCEventHandler = NewAEEventHandlerProc(MyHandleODOC);
  149.         myQAPPEventHandler = NewAEEventHandlerProc(MyHandleQUIT);
  150.         myOAPPEventHandler = NewAEEventHandlerProc(MyHandleOAPP);
  151.  
  152.         (void)AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,myOAPPEventHandler,0,false);    
  153.         (void)AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,myQAPPEventHandler,0,false);
  154.         (void)AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,myODOCEventHandler,0,false);
  155.         }
  156. }
  157.  
  158.  
  159. // *****************************************************************************
  160. main()
  161. {
  162.     long result = 0;
  163.     OSErr theErr = noErr;
  164.     
  165.     InitializeToolbox();
  166.     InitializeGlobals();
  167.     InstallEventHandlers();
  168.     SetupMenus();
  169.     
  170.     myActionProcUPP = NewControlActionProc(ScrollProc);
  171.  
  172.     AdjustMenus();
  173.  
  174.     EventLoop();
  175.  
  176.     theErr = Gestalt(gestaltAppleEventsAttr,&result);
  177.     if (theErr != noErr)
  178.         {
  179.         DisposeRoutineDescriptor(myODOCEventHandler);
  180.         DisposeRoutineDescriptor(myQAPPEventHandler);
  181.         DisposeRoutineDescriptor(myOAPPEventHandler);
  182.         }
  183.  
  184.     DisposeRoutineDescriptor(myActionProcUPP);
  185.  
  186.     return 0;
  187. }
  188.